using MicroMsg.Common.Utils;
using MicroMsg.UI.Page;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MicroMsg.UI.UserContrl
{
	public class VoiceHint : ContentControl
	{
		public enum State
		{
			Hide,
			Prepare,
			Show,
			CancelTip,
			CancelComfirm
		}
		private VoiceHint.State cuState;
		private Image SigImg;
		private Image SigImg2;
		private Grid PrepareGrid;
		private StackPanel RecordPanel;
		private StackPanel CancelPanel;
		private ImageBrush cancelImageBrush;
		private TextBlock CancelTxtBlock;
		public static DependencyProperty SignWeightProperty = DependencyProperty.Register("SignWeight", typeof(int), typeof(VoiceHint), new PropertyMetadata(1, new PropertyChangedCallback(VoiceHint.OnItemPropertyChanged)));
		private bool _contentLoaded;
		public VoiceHint.State CuState
		{
			get
			{
				return this.cuState;
			}
			set
			{
				this.cuState = value;
				this.RefreshState();
			}
		}
		public int SignWeight
		{
			get
			{
				return (int)base.GetValue(VoiceHint.SignWeightProperty);
			}
			set
			{
				base.SetValue(VoiceHint.SignWeightProperty, value);
			}
		}
		public VoiceHint()
		{
			this.InitializeComponent();
		}
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			this.SigImg = (base.GetTemplateChild("SigImg") as Image);
			this.SigImg2 = (base.GetTemplateChild("SigImg2") as Image);
			this.CancelTxtBlock = (base.GetTemplateChild("CancelTxtBlock") as TextBlock);
			this.PrepareGrid = (base.GetTemplateChild("PrepareGrid") as Grid);
			this.RecordPanel = (base.GetTemplateChild("RecordPanel") as StackPanel);
			this.CancelPanel = (base.GetTemplateChild("CancelPanel") as StackPanel);
			this.cancelImageBrush = (base.GetTemplateChild("cancelImageBrush") as ImageBrush);
			if (this.CancelTxtBlock != null && R.isEnglish())
			{
				this.CancelTxtBlock.set_FontSize(21.0);
			}
			this.RefreshSig();
			this.RefreshState();
		}
		private void RefreshSig()
		{
			if (this.SigImg == null && this.SigImg2 == null)
			{
				return;
			}
			int num = this.SignWeight;
			num = Math.Max(num, 1);
			num = Math.Min(num, 8);
			string text = string.Format("/Resource/Img/Chat/sig{0}.png", num);
			if (this.SigImg != null)
			{
				this.SigImg.set_Source(new ImageSourceConverter().ConvertFromString(text) as ImageSource);
			}
			if (this.SigImg2 != null)
			{
				this.SigImg2.set_Source(new ImageSourceConverter().ConvertFromString(text) as ImageSource);
			}
		}
		private void RefreshState()
		{
			if (this.PrepareGrid == null || this.RecordPanel == null || this.CancelPanel == null || this.cancelImageBrush == null)
			{
				return;
			}
			if (this.cuState == VoiceHint.State.Hide)
			{
				base.set_Visibility(1);
				return;
			}
			if (this.cuState == VoiceHint.State.Prepare)
			{
				base.set_Visibility(0);
				this.PrepareGrid.set_Visibility(0);
				this.RecordPanel.set_Visibility(1);
				this.CancelPanel.set_Visibility(1);
				return;
			}
			if (this.cuState == VoiceHint.State.Show)
			{
				base.set_Visibility(0);
				this.PrepareGrid.set_Visibility(1);
				this.RecordPanel.set_Visibility(0);
				this.CancelPanel.set_Visibility(1);
				return;
			}
			if (this.cuState == VoiceHint.State.CancelTip)
			{
				base.set_Visibility(0);
				this.PrepareGrid.set_Visibility(1);
				this.RecordPanel.set_Visibility(1);
				this.CancelPanel.set_Visibility(0);
				ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
				string text = string.Format("/Resource/Img/Chat/VoiceHintCancelRightNormal.png", new object[0]);
				this.cancelImageBrush.set_ImageSource((ImageSource)imageSourceConverter.ConvertFromString(text));
				return;
			}
			base.set_Visibility(0);
			this.PrepareGrid.set_Visibility(1);
			this.RecordPanel.set_Visibility(1);
			this.CancelPanel.set_Visibility(0);
			ImageSourceConverter imageSourceConverter2 = new ImageSourceConverter();
			string text2 = string.Format("/Resource/Img/Chat/VoiceHintCancelPressed.png", new object[0]);
			this.cancelImageBrush.set_ImageSource((ImageSource)imageSourceConverter2.ConvertFromString(text2));
		}
		private static void OnItemPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == VoiceHint.SignWeightProperty)
			{
				(dependencyObject_0 as VoiceHint).OnSignWeightPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void OnSignWeightPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			try
			{
				this.RefreshSig();
			}
			catch (Exception ex)
			{
				Log.smethod_1(base.GetType().get_Name(), ex.get_StackTrace());
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Chat/VoiceHint.xaml", 2));
		}
	}
}
